<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

use Spatie\Permission\Traits\HasRoles;
use EloquentFilter\Filterable;
class User extends Authenticatable
{
    use HasRoles;
    use Notifiable;
    use Filterable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'qq', 'password', 'kouliang', 'role', 'parent_id', 'price', 'kouliang_min'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];


    public function sites()
    {
        return $this->hasMany(Site::class);
    }

    public function videos()
    {
        return $this->hasMany(UserVideo::class);
    }

    public function view_counts()
    {
        return $this->hasMany(ViewCount::class);
    }
    // 是否为 $user 的上级
    public function isSuperior($user)
    {
        return $this->id === $user->parent_id;
    }

    // 是否为 $user 的下级
    public function isSubordinate($user)
    {
        return $user->id === $this->parent_id;
    }

    public function subs()
    {
        return $this->hasMany(User::class, 'parent_id');
    }
    public function hasSuperior()
    {
        return $this->parent_id;
    }
    public function parent()
    {
        return $this->belongsTo(User::class);
    }

    public function feedbacks()
    {
        return $this->hasMany(FeedBack::class);
    }
}
